//
//  ErlyMate.mm
//  ErlyMate
//
//  Created by Roberto Saccon on 12/1/07.
//  Copyright 2007 Skast, LLC. All rights reserved.
//

#import "ErlyMate.h"
#import "MethodSwizzle.h"

@implementation ErlyMate

- (id)initWithPlugInController:(id <TMPlugInController>)aController
{
	self = [self init];
	NSApp = [NSApplication sharedApplication];
	
	if(self = [super init])
	{
		NSTask *erlymate=[[NSTask alloc] init];    
		[erlymate setLaunchPath:@"/Users/rsaccon/bin/erl"];  
		[erlymate setArguments:[NSArray arrayWithObjects:@"-pa",@"/Users/rsaccon/opensource/erlymate/ebin",@"-run",@"erlymate",@"server",@"0.1",@"17779",@"secretcookie",@"-noinput",@"&",nil]];
		[erlymate launch];    
		[erlymate release];
	}
	
	[[NSNotificationCenter defaultCenter] addObserver:self
	 selector:@selector(applicationWillTerminate:)
	 name:NSApplicationWillTerminateNotification object:nil];

	return self;
}

- (void)applicationWillTerminate:(NSNotification*)notification
{
	NSTask *erlymate=[[NSTask alloc] init];    
	[erlymate setLaunchPath:@"/Users/rsaccon/opensource/erlymate/bin/erlymate"];  
	[erlymate setArguments:[NSArray arrayWithObjects:@"stop",nil]];
	[erlymate launch];    
	[erlymate release];
}

@end
